package com.tyjc.unique;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.tyjc.unique.dlt.DltColdHotFragment;
import com.tyjc.unique.dlt.DLTLuckyNumFragment;
import com.tyjc.unique.dlt.DLTThendFragment;
import com.tyjc.unique.dlt.DltVerifyPrizeFragment;
import com.tyjc.unique.dlt.DltFilterFragment;
import com.tyjc.unique.dlt.PhaseSkipFragment;
import com.tyjc.unique.ssq.BaseFragment;
import com.fyzk.base.BaseActivity;
import com.tyjc.lottery.R;
import com.fyzk.utils.IntentParamUtils;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

/**
 * Created by miao on 2017/1/6.
 */
@ContentView(R.layout.app_bar_home_main)
public class DLTUniqueActivity extends BaseActivity {
    @ViewInject(R.id.main_pager)
    ViewPager viewPager;

    @ViewInject(R.id.toolbar)
    Toolbar toolbar;
    @ViewInject(R.id.toolbar_title)
    TextView toolbar_title;

    BaseFragment[] pagers;

    public static final int FILTER = 0;
    public static final int TREND = 1;
    public static final int COLDHOT = 2;
    public static final int LUCKYNUM = 3;
    public static final int PHASESKIP = 4;
    public static final int PRIZEVERFY = 5;

    private int showFunction = FILTER;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(toolbar);
        toolbar_title.setText("大乐透"+getString(R.string.function_filter));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        viewPager.addOnPageChangeListener(pageChangeListener);
        viewPager.setAdapter(new DLTUniqueActivity.UniquePageAdapter(getSupportFragmentManager()));
    }

    @Override
    protected void onResume() {
        super.onResume();
        showFunction = getIntent().getIntExtra(IntentParamUtils.FUNCTION,TREND);
        viewPager.setCurrentItem(showFunction);
    }

    BaseFragment curFragment;

    ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int
                positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            curFragment = pagers[position];
            curFragment.showData();
            switch (position) {
                case PRIZEVERFY:
                    toolbar_title.setText("大乐透"+getString(R.string.function_prizeverify));
                    break;
                case COLDHOT:
                    toolbar_title.setText("大乐透"+getString(R.string.function_coldhot));
                    break;
                case FILTER:
                    toolbar_title.setText("大乐透"+getString(R.string.function_filter));
                    break;
                case TREND:
                    toolbar_title.setText("大乐透"+getString(R.string.function_trendchart));
                    break;
                case PHASESKIP:
                    toolbar_title.setText("大乐透"+getString(R.string.function_omit));
                    break;
                case LUCKYNUM:
                    toolbar_title.setText("大乐透"+getString(R.string.function_lucky5));
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };
    class UniquePageAdapter extends FragmentPagerAdapter {
        public UniquePageAdapter(FragmentManager fm) {
            super(fm);
            pagers = new BaseFragment[6];
            pagers[0] = new DltFilterFragment();
            pagers[1] = new DLTThendFragment();
            pagers[2] = new DltColdHotFragment();
            pagers[3] = new DLTLuckyNumFragment();
            pagers[4] = new PhaseSkipFragment();
            pagers[5] = new DltVerifyPrizeFragment();
        }

        @Override
        public Fragment getItem(int position) {
            return pagers[position];
        }

        @Override
        public int getCount() {
            return pagers.length;
        }
    }


    @Override
    public void onStart() {
        super.onStart();
        com.fyzk.utils.LogUtil.v("onStart>>>>>>>>>>>>>>>>");
    }

    @Override
    public void onPause() {
        super.onPause();
        com.fyzk.utils.LogUtil.v("onPause >>>>>>>>>>>>>>>>");
    }





}
